/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-10
 * Time: 18:58
 */
class Counter {
    int count = 0;
    synchronized public  void increase() {
        count++ ;
    }
}
public class demo01 {

    public static void main(String[] args)  {
        Counter con = new Counter();
        Thread t1 =new Thread() {
            @Override
            public void run() {
              for(int i=0;i<50000;i++) {
                   con.increase();

                }
            }
        };

        Thread t2 =new Thread() {
            @Override
            public void run() {
                for(int i=0;i<50000;i++) {
                    con.increase();
                }
            }
        };

        t1.start();;
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(con.count);

    }
}
